package com.tools.cleanmaster.store;

import android.content.Context;
import android.content.SharedPreferences;

import com.tools.cleanmaster.CleanApplication;

/**
 * 结果页配置
 * Created by wen.yu.gang on 15/11/4.
 */
public class ResultPageSharedPrefManager {
    private static SharedPreferences sPrefs = null;

    private static final String KEY_CLOUD_CARD_SWITCH = "_switch";
    private static final String KEY_CLOUD_RATE_PRESS = "rate_press_new";//1.4.8.6改变key名,重新计数
    private static final String KEY_CLOUD_RESULT_SHOW_TIME = "result_show_time";


    private final static String PREFS_FILE = "result_card_info";

    //记录是否默认勾选状态清理
    private static final String KEY_LAST_CLEAN_ALL_DEFAULT = "last_clean_default";

    //结果页卡片展示次数 计数,1.4.8.6开始
    private static final String KEY_IS_RATING_DIALOG_BUTTON_CLICK = "rating_dialog_click";//记录5星好评是否已经点击过

    private static SharedPreferences initSharedPreferences(Context context) {
        if (sPrefs == null) {
            sPrefs = context.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE);
        }
        return sPrefs;
    }

    /**
     * 获取是否启用场景化新结果页
     */
    public static boolean isCloudResultPageSwitch(Context ctx) {
        SharedPreferences prefs = initSharedPreferences(ctx);
        return true;
    }


    /**
     * 获取卡片开关
     *
     * @param cxt
     * @param key
     * @return
     */
    public static boolean isCloudCardSwitch(Context cxt, String key) {
        SharedPreferences prefs = initSharedPreferences(cxt);
        return prefs.getBoolean(key + KEY_CLOUD_CARD_SWITCH, true);
    }


    /**
     * 设置rate点击过
     */
    public static void setRatePress(Context cxt) {
        SharedPreferences prefs = initSharedPreferences(cxt);
        SharedPreferencesCompat.apply(prefs.edit().putBoolean(KEY_CLOUD_RATE_PRESS, true));
    }

    /**
     * 获取rate是否点击过
     */
    public static boolean getRatePress(Context cxt) {
        SharedPreferences prefs = initSharedPreferences(cxt);
        return prefs.getBoolean(KEY_CLOUD_RATE_PRESS, false);
    }

    /**
     * 设置结果页首次展示时间
     */
    public static void setResultFirstShowTime(Context cxt) {
        SharedPreferences prefs = initSharedPreferences(cxt);
        SharedPreferencesCompat.apply(prefs.edit().putLong(KEY_CLOUD_RESULT_SHOW_TIME, System.currentTimeMillis()));
    }

    /**
     * 获取结果页首次展示时间
     *
     * @return
     */
    public static long getResultFirstShowTime(Context cxt) {
        SharedPreferences prefs = initSharedPreferences(cxt);
        return prefs.getLong(KEY_CLOUD_RESULT_SHOW_TIME, 0);
    }


    /**
     * 清理时，用户是否进行默认勾选操作
     *
     * @param isAll
     */
    public static void setLastCleanAllDefault(boolean isAll) {
        Context appContext = CleanApplication.getInstance();
        SharedPreferences prefs = initSharedPreferences(appContext);
        SharedPreferencesCompat.apply(prefs.edit().putBoolean(KEY_LAST_CLEAN_ALL_DEFAULT, isAll));
    }

    /**
     * 获取清理时，用户是否进行默认勾选操作
     *
     * @return
     */
    public static boolean isLastCleanAllDefault() {
        Context appContext = CleanApplication.getInstance();
        SharedPreferences prefs = initSharedPreferences(appContext);
        return prefs.getBoolean(KEY_LAST_CLEAN_ALL_DEFAULT, true);
    }

    /**
     * 设置评分卡片dialog已经展示过
     */
    public static void setRatingDialogRightButtonClick(Context cxt) {
        SharedPreferences prefs = initSharedPreferences(cxt);
        SharedPreferencesCompat.apply(prefs.edit().putBoolean(KEY_IS_RATING_DIALOG_BUTTON_CLICK, true));
    }
}
